package net.mlike.openssp.server.search;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;

import javax.persistence.Transient;

/**
 * Created by wallellen@hotmail.com on 5/24/18.
 */
public class BaseSearch extends PageRequest {
    /**
     * Creates a new {@link PageRequest}. Pages are zero indexed, thus providing 0 for {@code page} will return the first
     * page.
     *
     * @param page zero-based page index.
     * @param size the size of the page to be returned.
     * @deprecated use {@link #of(int, int)} instead.
     */
    public BaseSearch(int page, int size) {
        super(page, size);
    }

    public BaseSearch() {
        super(0, 10);
    }

    private int page;
    private int size;

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    @Transient
    public final Specification getCondition() {
        return buildCondition();
    }

    protected Specification buildCondition() {
        return (Specification) (root, query, criteriaBuilder) -> null;
    }
}
